package com.oa.process.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.oa.common.result.Result;
import com.oa.model.process.Process;
import com.oa.process.service.OaProcessService;
import com.oa.vo.process.ApprovalVo;
import com.oa.vo.process.ProcessFormVo;
import com.oa.vo.process.ProcessQueryVo;
import com.oa.vo.process.ProcessVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 审批类型 前端控制器
 * </p>
 *
 * @author cloud_oa
 * @since 2024-11-05
 */

@RestController
@Api(tags = "审批流管理")
@RequestMapping("/admin/process")
public class OaProcessController {
    @Autowired
    private OaProcessService oaProcessService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(
            @ApiParam(name="page",value="当前页码",required=true)
            @PathVariable Long page,
            @ApiParam(name="limit",value="每页记录数",required=true)
            @PathVariable Long limit,
            @ApiParam(name="processQueryVo",value="查询对象",required=false)
            ProcessQueryVo processQueryVo
    ){
        Page<ProcessVo> pageParam = new Page<>(page,limit);
        IPage<ProcessVo> pageModel = oaProcessService.selectPage(pageParam,processQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value="待处理审批列表")
    @GetMapping(value="findPending/{page}/{limit}")
    public Result findPending(@ApiParam(name="page",value = "当前页码", required = true)
                              @PathVariable Long page,
                              @ApiParam(name="limit",value="每页记录数",required = true)
                              @PathVariable Long limit){
        Page<Process> pageParam = new Page<>(page,limit);
        return Result.ok(oaProcessService.findPending(pageParam));
    }

    @ApiOperation(value = "获取审批详请")
    @GetMapping(value="show/{id}")
    public Result show(@PathVariable Long id){
        Map<String,Object> map = oaProcessService.show(id);
        return Result.ok(map);
    }

    @ApiOperation(value="审批")
    @PostMapping(value = "approve")
    public Result approve(@RequestBody ApprovalVo approvalVo){
        oaProcessService.approve(approvalVo);
        return Result.ok();
    }

}

